<?php
    if ($db = new SQLiteDatabase('logger.db')) {
		$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='events'");
		if ($result->numRows() == 0) {
			$db->queryExec('CREATE TABLE events (
				ip text, 
				ts int,
				category text,
				event text,
				condition text,
				extra text)');
		}
	}
	$ip = $_SERVER['REMOTE_ADDR'];
	$category = sqlite_escape_string($_REQUEST['category']);
	$event = sqlite_escape_string($_REQUEST['event']);
	$condition = sqlite_escape_string($_REQUEST['condition']);
	$extra = sqlite_escape_string($_REQUEST['extra']);
	$timestamp = time();
	
	$statement = "INSERT INTO events (ip,ts, category,event,condition,extra) VALUES('%s', %d, '%s', '%s', '%s', '%s')";
	$to_execute = sprintf($statement, $ip, $timestamp, $category, $event, $condition, $extra);
	$db->queryExec($to_execute);

?>